
export const state = () => {
  return {
  }
}

export const mutations = {
}

export const actions = {
  /**
   * 请求封装
   * @param state
   * @param params 请求信息{apiData:{url:String,method:String},params:{}}
   * @returns {AxiosPromise} 请求结果Promise对象
   */
  fetch({state},params){
    let reqJob = {}
    if(params && params.apiData){
      if(apiData.method === "get" && params.params){
        //拼接地址栏参数
        let url = params.apiData.url
        url = url + "?"
        //遍历参数对象集合
        Object.keys(params.params).forEach(item => {
          let param = item + "=" + params.params[item] + "&"
          url = url + param
        })
        reqJob.url = url
      }else if(params.apiData.method === 'POST'){
        reqJob = {...params.apiData}
        //将表单数据转换成json格式
        reqJob.data = JSON.stringify(params.data)
      }
    }
    return this.$axios(reqJob)
  }
}

export default {
  namespace:true,
  state,
  mutations,
  actions
}
